var GlobalErrorListener = require('./GlobalErrorListener');
var dataUtils = require('./dataUtils');
var DataGroup = require('./DataGroup');
var Event = require('./Event');
var Behavior = require('./Behavior');
var Element = require('./Element');
var NativeNode = require('./NativeNode');
var Observer = require('./Observer');
var ClassList = require('./ClassList');
var FakeDomElement = require('./FakeDomElement');
var globalOptions = require('./globalOptions');
var globalState = require('./globalState');
var dataPath = require('./dataPath');
var addListenerToElement = Event.addListenerToElement;
var parseSinglePath = dataPath.parseSinglePath;
var deepCopy = dataUtils.deepCopy;
var Component = function () {
};
Component.prototype = Object.create(Element.prototype, {
    constructor: {
        value: Component,
        writable: true,
        configurable: true
    },
    data: {
        get: function () {
            return this.__dataProxy._data;
        },
        set: function (e) {
            var t = this.__dataProxy;
            for (var i in e)
                t.scheduleReplace([i], e[i]);
            t.doUpdates();
        },
        configurable: true
    },
    $: {
        get: function () {
            Element._updateIdMap(this);
            return this.__idCache;
        },
        set: function () {
        }
    }
});
var m = function () {
};
m.prototype = Object.create(Object.prototype);
Event._setComponent(Component);
var I = null;
Component._setDefaultTemplateEngine = function (e) {
    I = e;
    Component._setDefaultTemplateEngine = null;
};
DataGroup.setPropUpdater(function (e, t, i, a) {
    var r = e[0];
    var o = this.__propData[r];
    i = function (e, t, i, a, r) {
        if (i)
            for (var o = 0; o < i.length; o++)
                if (Behavior.matchTypeWithValue(i[o], e))
                    return e;
        return t === String ? null == e ? (GlobalErrorListener.hasGlobalWarningListeners() && GlobalErrorListener.triggerWarning('property "' + r + '" of "' + (a.is || '') + '" received type-uncompatible value: expected <String> but get null value. Use empty string instead.'), '') : (GlobalErrorListener.hasGlobalWarningListeners() && 'object' == typeof e && GlobalErrorListener.triggerWarning('property "' + r + '" of "' + (a.is || '') + '" received type-uncompatible value: expected <String> but got object-typed value. Force converted.'), String(e)) : t === Number ? isFinite(e) ? Number(e) : (GlobalErrorListener.hasGlobalWarningListeners() && ('number' == typeof e ? GlobalErrorListener.triggerWarning('property "' + r + '" of "' + (a.is || '') + '" received type-uncompatible value: expected <Number> but got NaN or Infinity. Used 0 instead.') : GlobalErrorListener.triggerWarning('property "' + r + '" of "' + (a.is || '') + '" received type-uncompatible value: expected <Number> but got non-number value. Used 0 instead.')), 0) : t === Boolean ? !!e : t === Array ? e instanceof Array ? e : (GlobalErrorListener.hasGlobalWarningListeners() && GlobalErrorListener.triggerWarning('property "' + r + '" of "' + (a.is || '') + '" received type-uncompatible value: expected <Array> but got non-array value. Used empty array instead.'), []) : t === Object ? 'object' == typeof e ? e : (GlobalErrorListener.hasGlobalWarningListeners() && GlobalErrorListener.triggerWarning('property "' + r + '" of "' + (a.is || '') + '" received type-uncompatible value: expected <Object> but got non-object value. Used null instead.'), null) : undefined === e ? null : e;
    }(i, t.type, t.optionalTypes, this, r);
    var l = !t.availability || function (e, t, i, a) {
        var r = [
            e.ownerShadowRoot ? e.ownerShadowRoot.__wxHost.__componentOptions.domain : undefined,
            a ? undefined : i
        ];
        return !!GlobalErrorListener.safeCallback('Availablity Controller', t, e.__methodCaller, r, e);
    }(this, t.availability, i, a);
    if (!l) {
        GlobalErrorListener.hasGlobalWarningListeners() && GlobalErrorListener.triggerWarning('the new value for property "' + r + '" in component "' + (this.is || '') + '" is currently not available. The value is not changed.');
        return o;
    }
    if (t.filter) {
        var d = GlobalErrorListener.safeCallback('Property Filter', t.filter, this.__methodCaller, a ? [] : [
            i,
            o,
            e
        ], this);
        undefined !== d && (i = d);
    }
    this.__domElement && this.__componentOptions.reflectToAttributes && this.__propPublic[r] && function (e, t, i, n) {
        if (n && e.ownerShadowRoot) {
            var a = e.ownerShadowRoot.__wxHost.__idPrefix;
            a && (i = a + '--' + i);
        }
        var r = t.replace(/[A-Z]/g, function (e) {
            return '-' + e.toLowerCase();
        });
        var o = typeof i;
        if ('boolean' === o) {
            i ? e.__domElement.setAttribute(r, '') : e.__domElement.removeAttribute(r);
        } else {
            'object' === o ? e.__domElement.setAttribute(r, JSON.stringify(i)) : e.__domElement.setAttribute(r, i);
        }
    }(this, r, i, t.reflectIdPrefix);
    return i;
});
DataGroup.setPropObserver(function (e, t, i, a, r, o) {
    if (a.observeAssignments || e !== t) {
        var s = i[0];
        this.__propertyChangeListeners && this.__propertyChangeListeners[s] && !o && GlobalErrorListener.safeCallback('Property Observer', this.__propertyChangeListeners[s], this.__methodCaller, [e], this);
        a.observer && GlobalErrorListener.safeCallback('Property Observer', a.observer, this.__methodCaller, r ? [] : [
            e,
            t,
            i
        ], this);
        a.public && (this.__propObservers && !this.__propObservers.empty || this.__subtreeObserversCount) && Observer._callObservers(this, '__propObservers', {
            type: 'properties',
            target: this,
            propertyName: s
        });
    }
});
var b = function (e, t, i) {
    t.__relationLinks || (t.__relationLinks = {});
    var n = t.__relationLinks[i] = [];
    for (var a = 0; a < e.length; a++)
        n.push(null);
};
var C = function (e, t, i, a, r) {
    var o = Component.prototype.hasBehavior;
    var d = 'parent' === a;
    var A = 'shadowHost' === a;
    for (var c = 0; c < e.length; c++) {
        var h = e[c];
        var u = null;
        if (u = 'object' != typeof h.target ? Behavior._list[h.target] : h.target) {
            var p = t[c];
            var g = null;
            if (!r)
                for (var _ = A ? i.ownerShadowRoot && i.ownerShadowRoot.__wxHost : i.parentNode; _; _ = A ? _.ownerShadowRoot && _.ownerShadowRoot.__wxHost : _.parentNode)
                    if (Element.isSelectable(_)) {
                        if (o.call(_, u)) {
                            var f = null;
                            f = d ? _.__relationMap.child : A ? _.__relationMap.shadowContent : _.__relationMap.descendant;
                            for (var v = 0; v < f.length; v++) {
                                var m = f[v];
                                var I = null;
                                if ((I = 'object' != typeof m.target ? Behavior._list[m.target] : m.target) && o.call(i, I)) {
                                    g = {
                                        parent: _,
                                        relation: m
                                    };
                                    break;
                                }
                            }
                        }
                        if (d || g)
                            break;
                    }
            t[c] = g;
            if (!(!p || g && p.parent === g.parent)) {
                GlobalErrorListener.safeCallback('Relation Unlinked Callback', p.relation.unlinked, p.parent.__methodCaller, [i.__methodCaller], p.parent);
                GlobalErrorListener.safeCallback('Relation Unlinked Callback', h.unlinked, i.__methodCaller, [p.parent.__methodCaller], i);
            };
            if (!(!g || p && p.parent === g.parent)) {
                GlobalErrorListener.safeCallback('Relation Linked Callback', g.relation.linked, g.parent.__methodCaller, [i.__methodCaller], g.parent);
                GlobalErrorListener.safeCallback('Relation Linked Callback', h.linked, i.__methodCaller, [g.parent.__methodCaller], i);
            };
            if (p && g && p.parent === g.parent) {
                GlobalErrorListener.safeCallback('Relation Link Changed Callback', g.relation.linkChanged, g.parent.__methodCaller, [i.__methodCaller], g.parent);
                GlobalErrorListener.safeCallback('Relation Link Changed Callback', h.linkChanged, i.__methodCaller, [g.parent.__methodCaller], i);
            };
            r || g || GlobalErrorListener.safeCallback('Relation Link Failed Callback', h.linkFailed, i.__methodCaller, [], i);
        }
    }
};
var y = function (e, t, i) {
    if (e instanceof Element) {
        var n = 0;
        var a = null;
        if (e instanceof Component) {
            e.__pageLifeTimeFuncs[t] && e.__pageLifeTimeFuncs[t].call(e.__methodCaller, i || []);
            a = e.childNodes;
            for (n = 0; n < a.length; n++)
                y(a[n], t, i);
            e = e.shadowRoot;
        }
        a = e.childNodes;
        for (n = 0; n < a.length; n++)
            y(a[n], t, i);
    }
};
Component._list = {};
Component.register = function (e) {
    var t = e.options || {};
    var i = Behavior.create(e);
    var n = undefined !== t.classPrefix ? t.classPrefix : globalOptions.classPrefix;
    null == n && (n = i.is || '');
    var a = new m();
    a._unprepared = i;
    a.is = e.is || '';
    a.behavior = i;
    a.protoFunc = null;
    a.props = null;
    a.template = null;
    a.innerEvents = null;
    a.generics = i.generics;
    a.placeholder = i.placeholder;
    a.initiator = i.initiator || null;
    a.options = {
        availability: t.availability || globalOptions.availability,
        domain: t.domain || globalOptions.domain,
        writeOnly: !!(undefined !== t.writeOnly ? t.writeOnly : globalOptions.writeOnly),
        allowInWriteOnly: !!(undefined !== t.allowInWriteOnly ? t.allowInWriteOnly : globalOptions.allowInWriteOnly),
        classPrefix: n,
        addGlobalClass: !!(undefined !== t.addGlobalClass ? t.addGlobalClass : globalOptions.addGlobalClass),
        templateEngine: t.templateEngine || globalOptions.templateEngine || I,
        renderingMode: t.renderingMode || globalOptions.renderingMode,
        multipleSlots: !!(undefined !== t.multipleSlots ? t.multipleSlots : globalOptions.multipleSlots),
        reflectToAttributes: !!(undefined !== t.reflectToAttributes ? t.reflectToAttributes : globalOptions.reflectToAttributes),
        writeFieldsToNode: !!(undefined !== t.writeFieldsToNode ? t.writeFieldsToNode : globalOptions.writeFieldsToNode),
        writeIdToDOM: !!(undefined !== t.writeIdToDOM ? t.writeIdToDOM : globalOptions.writeIdToDOM),
        idPrefixGenerator: t.idPrefixGenerator || globalOptions.idPrefixGenerator,
        separateInnerData: !!(undefined !== t.separateInnerData ? t.separateInnerData : globalOptions.separateInnerData),
        innerDataExclude: t.innerDataExclude || globalOptions.innerDataExclude,
        listenerChangeLifeTimes: !!(undefined !== t.listenerChangeLifeTimes ? t.listenerChangeLifeTimes : globalOptions.listenerChangeLifeTimes),
        randomizeTagName: !!(undefined !== t.randomizeTagName ? t.randomizeTagName : globalOptions.randomizeTagName),
        virtualHost: !!(undefined !== t.virtualHost ? t.virtualHost : globalOptions.virtualHost)
    };
    i._unprepared || Component.prepare(a);
    undefined !== e.is && (Component._list[i.is] = a);
    return a;
};
Component.isPrepared = function (e) {
    return !e._unprepared;
};
Component.prepare = function (e) {
    var t = e._unprepared;
    if (t) {
        e._unprepared = null;
        var i = e.options;
        var a = {};
        t._unprepared && Behavior.prepare(t);
        i.writeOnly && (a.data = { value: null });
        var o = e.props = {};
        Object.keys(t.properties).forEach(function (e) {
            var n = t.properties[e];
            o[e] = {
                type: n.type,
                optionalTypes: n.optionalTypes,
                value: n.value,
                filter: 'function' == typeof n.filter ? n.filter : null == n.filter ? null : t.methods[n.filter],
                observer: 'function' == typeof n.observer ? n.observer : null == n.observer ? null : t.methods[n.observer],
                public: n.public,
                availability: n.availability,
                observeAssignments: n.observeAssignments,
                reflectIdPrefix: n.reflectIdPrefix
            };
            i.writeFieldsToNode && (a[e] = {
                enumerable: true,
                get: function () {
                    return this.__propData[e];
                },
                set: function (t) {
                    var i = this.__dataProxy;
                    i.scheduleReplace([e], t);
                    i.doUpdates();
                }
            });
        });
        var l = function () {
        };
        e.protoFunc = l;
        var d = l.prototype = Object.create(Component.prototype, a);
        d.is = e.is;
        d.__componentOptions = i;
        d.__using = t.using;
        e.dataGroupObserverTree = DataGroup._createObserverTree(o);
        t._addObserversToDataProxy(e.dataGroupObserverTree);
        d.__behavior = t;
        if (i.writeFieldsToNode)
            for (var A in t.methods)
                d[A] = t.methods[A];
        d.__lifeTimeFuncs = t._getAllLifeTimeFuncs();
        d.__pageLifeTimeFuncs = t._getAllPageLifeTimeFuncs();
        var c = t.relations;
        var h = d.__relationMap = {};
        for (var u in c) {
            var p = c[u];
            var g = p.type;
            h[g] ? h[g].push(p) : h[g] = [p];
        }
        var _ = [];
        h.parent && _.push(function (e) {
            C(this.__relationMap.parent, this.__relationLinks.parent, this, 'parent', 'detached' === e);
        });
        h.ancestor && _.push(function (e) {
            C(this.__relationMap.ancestor, this.__relationLinks.ancestor, this, 'ancestor', 'detached' === e);
        });
        h.shadowHost && _.push(function (e) {
            C(this.__relationMap.shadowHost, this.__relationLinks.shadowHost, this, 'shadowHost', 'detached' === e);
        });
        e.relationHandler = function (e) {
            for (var t = 0; t < _.length; t++)
                _[t].call(this, e);
        };
        var f = {};
        var v = {};
        var m = t.data;
        var I = '';
        for (I in m)
            v[I] = m[I];
        for (I in o) {
            var b = o[I];
            GlobalErrorListener.hasGlobalWarningListeners() && undefined !== v[I] && GlobalErrorListener.triggerWarning('data field "' + I + '" is overwritten by property with the same name (when preparing "' + t.is + '").');
            v[I] = b.value;
            f[I] = b.public;
        }
        var y = v;
        var E = i.separateInnerData;
        var x = i.innerDataExclude;
        if (x) {
            for (var B in (y = {}, v))
                x.test(B) || (y[B] = v[B]);
            E || (v = y);
        }
        var S = i.templateEngine;
        e.template = S.create(t, v, y, i);
        d.__propPublic = f;
        var Q = t._getAllListeners();
        var k = e.innerEvents = [];
        for (var D in Q) {
            var M = Q[D];
            var N = D.indexOf('.');
            var T = D.slice(N + 1);
            var R = N < 1 ? '' : D.slice(0, N);
            var L = [];
            for (var P = 0; P < M.length; P++) {
                var F = M[P];
                'function' != typeof F && (F = null == F ? null : t.methods[F]);
                L.push(F);
            }
            k.push({
                id: R,
                name: T,
                funcs: L
            });
        }
    }
};
var E = 1;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var B = function (e, t) {
    return function (i) {
        return e.call(t.__methodCaller, i, t);
    };
};
var S = Component._advancedCreate = function (e, t, i, a, o, s) {
    var d = t;
    d._unprepared && Component.prepare(d);
    var A = d.options;
    var g = !A.availability || function (e, t, i) {
        var a = [t ? t.__wxHost.__componentOptions.domain : undefined];
        return !!GlobalErrorListener.safeCallback('Availablity Controller', i, e, a);
    }(d, i, A.availability);
    if (!g) {
        GlobalErrorListener.hasGlobalWarningListeners() && GlobalErrorListener.triggerWarning('the component "' + (d.is || '') + '" is currently not available. The default component is used instead.');
        d = Component._list[''];
    };
    var f = new (0, d.protoFunc)();
    A.idPrefixGenerator && (f.__idPrefix = String(A.idPrefixGenerator.call(f)));
    f.__placeholder = function (e, t) {
        var i = {};
        for (var n in t)
            i[n] = t[n];
        for (var n in e)
            i[n] = e[n];
        return i;
    }(o, d.placeholder);
    var m = d.generics;
    f.__generics = m ? function (e, t, i) {
        var a = {};
        for (var r in e) {
            var o = e[r];
            var s = t[r];
            'object' != typeof s && hasOwnProperty.call(Component._list, s) && (s = Component._list[s]);
            'object' != typeof s && null != o.default && (s = Component._list[o.default]);
            if (GlobalErrorListener.hasGlobalWarningListeners()) {
                s || GlobalErrorListener.triggerWarning('generic "' + r + '" is not instantiated. The default component is used instead.');
            };
            s && (a[r] = s);
        }
        if (GlobalErrorListener.hasGlobalWarningListeners())
            for (var l in t)
                undefined === e[l] && GlobalErrorListener.triggerWarning('generic "' + l + '" is not defined. It will be ignored.');
        return a;
    }(m, a || {}) : {};
    var I = null;
    var C = globalOptions.documentBackend;
    if (A.virtualHost) {
        I = null;
        'dom' === globalOptions.documentBackend && (I = undefined);
        Element.initialize(f, I, i);
        f.__virtual = true;
    } else
        'dom' === C ? (I = globalState.backendExtractedDefault ? new FakeDomElement(e) : document.createElement(e), Element.initialize(f, I, i)) : Element.initialize(f, null, i);
    var y = 0;
    var S = f.__externalClassAlias = {};
    if (d.behavior.externalClasses) {
        var Q = d.behavior.externalClasses;
        for (y = 0; y < Q.length; y++)
            S[Q[y]] = null;
    }
    f.classList = ClassList.create(f, S);
    if (i) {
        var k = i.__wxHost;
        f.classList._setOwnerOptions(k.classList, k.__componentOptions.classPrefix, k.__componentOptions.addGlobalClass);
        globalOptions.writeExtraInfoToAttr && I && I.setAttribute('exparser:info-class-prefix', k.__componentOptions.classPrefix && k.__componentOptions.classPrefix + '--');
    }
    if (globalOptions.writeExtraInfoToAttr && I) {
        f.__componentInstanceId = E++;
        I.setAttribute('exparser:info-component-id', f.__componentInstanceId);
    };
    var D = f.__templateInstance = d.template.createInstance(f, s);
    f.__propData = D.data;
    var M = A.separateInnerData;
    f.__innerData = M ? deepCopy(f.__propData) : null;
    var N = A.innerDataExclude;
    if (M && N) {
        var T = {};
        for (var R in f.__innerData)
            N.test(R) || (T[R] = f.__innerData[R]);
        f.__innerData = T;
    }
    f.__dataProxy = DataGroup._advancedCreate(f, f.__propData, f.__innerData, N, d.dataGroupObserverTree, function (e, t, i, n) {
        f.__templateInstance.updateValues(f, M ? f.__innerData : f.__propData, e, t, i, n);
    });
    D.beforeMergeValues && f.__dataProxy.setBeforeMergeCb(function (e, t, i) {
        f.__templateInstance.beforeMergeValues(e, t, i);
    });
    D.beforeUpdateValues && f.__dataProxy.setBeforeUpdateCb(function (e) {
        f.__templateInstance.beforeUpdateValues(f, M ? f.__innerData : f.__propData, e);
    });
    A.writeOnly && f.__dataProxy.setHidingValue(true);
    f.__idCacheDirty = false;
    f.__idCache = D.idMap;
    null === D.slots[''] && (D.slots[''] = I);
    if (d.options.multipleSlots) {
        f.__slots = D.slots;
    } else {
        f.__singleSlot = D.slots[''] || null;
        f.__singleSlot && (f.__singleSlot.__wxSlotChildren = f.childNodes);
    }
    D.shadowRoot instanceof Element ? (f.shadowRoot = D.shadowRoot, Element._attachShadowRoot(D.shadowRoot)) : I instanceof FakeDomElement ? (f.shadowRoot = I, I.__wxHost = f, f.__domElement.asShadowRoot = D.shadowRoot, f.__wxSlotChildren = [I], I.__wxSlotParent = f) : (f.shadowRoot = I, I.__wxHost = f, f.__domElement.appendChild(D.shadowRoot), f.__wxSlotChildren = [I], I.__wxSlotParent = f);
    var L = D.listeners;
    for (var P = 0; P < L.length; P++) {
        var F = L[P];
        addListenerToElement(F.target, F.name, B(F.func, f));
    }
    var O = d.innerEvents;
    for (y = 0; y < O.length; y++) {
        var U = O[y];
        var G = U.id ? 'this' === U.id ? f : f.__idCache[U.id] : f.shadowRoot;
        if (G)
            for (var j = U.name, V = U.funcs, W = 0; W < V.length; W++)
                addListenerToElement(G, j, B(V[W], f));
    }
    var H = f.__relationMap;
    if (H.parent) {
        b(H.parent, f, 'parent');
        f.__relationHandler = d.relationHandler;
    };
    if (H.ancestor) {
        b(H.ancestor, f, 'ancestor');
        f.__relationHandler = d.relationHandler;
    };
    if (H.shadowHost) {
        b(H.shadowHost, f, 'shadowHost');
        f.__relationHandler = d.relationHandler;
    };
    f.__propertyChangeListeners = null;
    d.initiator && GlobalErrorListener.safeCallback('Component Initiator', d.initiator, f.__methodCaller, [], f);
    f.__lifeTimeFuncs.created.call(f.__methodCaller, [], f);
    return f;
};
Component.createWithGenerics = function (e, t, i, a) {
    return 'object' == typeof e ? S(e.is, e, null, i, null, a) : e ? e.indexOf('-') < 0 && !t ? NativeNode.create(e) : (GlobalErrorListener.hasGlobalWarningListeners() && (t || hasOwnProperty.call(Component._list, e) || 'virtual' === e || GlobalErrorListener.triggerWarning('component "' + e + '" is not found. The default component is used instead.')), S(e.toLowerCase(), t || hasOwnProperty.call(Component._list, e) && Component._list[e] || Component._list[''], null, i, null, a)) : S('virtual', Component._list[''], null, i, null, a);
};
Component.create = function (e, t, i) {
    return Component.createWithGenerics(e, t, null, i);
};
Component.listProperties = function (e) {
    var t = [];
    for (var i in e.__propPublic)
        undefined !== e.__propPublic[i] && t.push(i);
    return t;
};
Component.listPublicProperties = function (e) {
    var t = [];
    for (var i in e.__propPublic)
        true === e.__propPublic[i] && t.push(i);
    return t;
};
Component.hasProperty = function (e, t) {
    return undefined !== e.__propPublic[t];
};
Component.hasPublicProperty = function (e, t) {
    return true === e.__propPublic[t];
};
Component.getMethodsFromDef = function (e) {
    e.behavior._unprepared && Behavior.prepare(e.behavior);
    return e.behavior.methods;
};
Component.getMethod = function (e, t) {
    return e.__behavior.methods[t];
};
Component.getComponentOptions = function (e) {
    return e.__componentOptions;
};
Component.prototype.triggerLifeTime = function (e, t) {
    this.__lifeTimeFuncs[e].call(this.__methodCaller, t || []);
};
Component.prototype.triggerPageLifeTime = function (e, t) {
    y(this, e, t);
};
Component.prototype.hasBehavior = function (e) {
    'object' != typeof e && Object.prototype.hasOwnProperty.call(this.__using, e) && (e = this.__using[e]);
    return !!this.__behavior && this.__behavior.hasBehavior(e);
};
Component.prototype.getRootBehavior = function () {
    return this.__behavior;
};
Component.prototype.getPlaceholder = function (e) {
    return this.__placeholder[e];
};
Component.prototype.getRelationNodes = function (e) {
    var t = this.__behavior.relations[e];
    if (!t)
        return null;
    if ('parent' === t.type || 'ancestor' === t.type || 'shadowHost' === t.type) {
        var i = this.__relationMap[t.type];
        for (var n = 0; n < i.length && i[n] !== t; n++);
        return this.__relationLinks[t.type][n] ? [this.__relationLinks[t.type][n].parent] : [];
    }
    return function (e, t) {
        var i = [];
        var n = t.type;
        var a = 'child' === n;
        var r = 'shadowContent' === n;
        var o = function (n) {
            var s = n.childNodes;
            for (var d = 0; d < s.length; d++) {
                var A = s[d];
                if (A instanceof Element)
                    if (Element.isSelectable(A)) {
                        if (A.__relationLinks) {
                            var c = null;
                            if (c = a ? A.__relationLinks.parent : r ? A.__relationLinks.shadowHost : A.__relationLinks.ancestor)
                                for (var h = 0; h < c.length; h++) {
                                    var u = c[h];
                                    if (u && u.parent === e && u.relation === t) {
                                        i.push(A);
                                        break;
                                    }
                                }
                        }
                        r && A instanceof Component && o(A.shadowRoot);
                        a || o(A);
                    } else
                        o(A);
            }
        };
        o(r ? e.shadowRoot : e);
        return i;
    }(this, t);
};
Component.prototype.hasExternalClass = function (e) {
    return hasOwnProperty.call(this.__externalClassAlias, e);
};
Component.prototype.setExternalClass = function (e, t) {
    this.classList._setAlias(e, t);
};
Component.prototype.setPropertyChangeListener = function (e, t) {
    this.__propertyChangeListeners || (this.__propertyChangeListeners = {});
    this.__propertyChangeListeners[e] = t;
};
Component.prototype.replaceDataOnPath = function (e, t) {
    this.__dataProxy.scheduleReplace(e, t);
};
Component.prototype.isInnerDataExcluded = function (e) {
    var t = this.__componentOptions.innerDataExclude;
    return !!t && t.test(e);
};
Component.getInnerData = function (e) {
    return e.__innerData;
};
Component.getDataProxy = function (e) {
    return e.__dataProxy;
};
Component.replaceWholeData = function (e, t, i) {
    e.__propData = t;
    e.__dataProxy.replaceWholeData(t, i);
};
Component.prototype.applyDataUpdates = function () {
    this.__dataProxy.doUpdates();
};
Component.prototype.setData = function (e) {
    var t = this.__dataProxy;
    for (var i in e)
        t.scheduleReplace(parseSinglePath(i), e[i]);
    t.doUpdates();
};
module.exports = Component;
